<?php

/*
* @Author: 玛瑙
* @Date:   2018-04-23 15:41:51
* @Last Modified by:   Administrator
* @Last Modified time: 2018-05-28 17:15:16
*/
namespace app\company\controller;

class Warning extends Common {

	/**
	 * 预警列表页
	 */
	public function index() {

		$data = input('post.');

		if(!empty($data['mobile'])) {
			$map['o.mobile'] = ['like',"%{$data['mobile']}%"];
		}

		$remind_day = get_value(session('company.company_id'),'company','id','remind_day','0');

		if(!empty($remind_day)) {
			$map['d.user_name'] = ['like',"%{$data['user_name']}%"];

			if(!empty($data['license_type'])) {
				$map['o.license_type'] = $data['license_type'];
			}

			$map['o.order_status'] = 3;

			$map['o.order_sn'] = ['like',"%{$data['order_sn']}%"];

			$map['o.next_time'] = ['elt', intval(mktime(0,0,0,date('m'),date('d'),date('Y'))) + "{$remind_day}" * 86400];
                        $map['o.finish_time'] = ['egt', intval(mktime(0,0,0,date('m'),date('d'),date('Y'))) - 730 * 86400];
		//页码
			$pageNum = 1;
			if (is_numeric(input('post.pageNum'))) {
				$pageNum = input('post.pageNum');
			}
        //每页数量
			$numPerPage = 20;
			$data['numPerPage'] = $numPerPage;

			$model = new \app\company\model\Sqd();

			$data['list'] = $model->get_list($map,$pageNum,$numPerPage,'');
			$data['count'] = $model->get_list($map,'','',1);

		}
        $data['vehicle'] = db('vehicle')->select();
		return view('',$data);
	}

	/**
	 * 到期提醒处理
	 */
	public function cl() {

		$data['order_id'] = input('get.order_id');

		return view('',$data);
	}

	/**
	 * 添加处理结果
	 */
	public function doCl() {

		$map = input('post.');

		try {
			doModify('order',$map);

		} catch (Exception $e) {
			return json([
				'statusCode' => 300,
				'message' => $e->getMessage(),
				]);
		}

		return json([
			'statusCode' => 200,
			'message' => '处理成功',
			'navTabId' => 'warning_manage'
			]);

	}
}